// CMS内容相关API

import { $api } from '~/utils/request'

export interface Banner {
  id: number
  title: string
  imageUrl: string
  linkUrl: string
  linkType: number // 1:内部链接 2:外部链接
  movieId?: number
  sort: number
  status: number
  createTime: string
}

export interface ShortVideo {
  id: number
  title: string
  coverUrl: string
  videoUrl: string
  description: string
  userId: number
  userName: string
  userAvatar: string
  likeCount: number
  commentCount: number
  shareCount: number
  status: number
  createTime: string
}

export interface Column {
  id: number
  name: string
  value: string
  icon: string
  type: number
  sort: number
  status: number
}

// 获取轮播图列表
export const getBannerList = () => {
  return $api.get<Banner[]>('/app/cms/banners')
}

// 获取栏目列表
export const getColumnList = () => {
  return $api.get<Column[]>('/app/basic/columns')
}

// 获取短视频列表
export const getShortVideoList = (pageNum: number = 1, pageSize: number = 20) => {
  return $api.get<{
    rows: ShortVideo[]
    total: number
  }>('/app/shorts/list', { pageNum, pageSize })
}

// 获取短视频详情
export const getShortVideoDetail = (id: number) => {
  return $api.get<ShortVideo>(`/app/shorts/${id}`)
}

// 点赞短视频（从JWT token获取userId）
export const likeShortVideo = (shortId: number) => {
  return $api.post(`/app/member/like`, { shortId })
}

// 增加短视频播放量
export const increaseShortPlayCount = (shortId: number) => {
  return $api.post(`/app/shorts/${shortId}/play`)
}

// 获取热门短视频
export const getHotShorts = (pageNum: number = 1, pageSize: number = 20) => {
  return $api.get<{
    rows: ShortVideo[]
    total: number
  }>('/app/shorts/hot', { pageNum, pageSize })
}

// 获取用户的短视频列表
export const getUserShorts = (userId: number, pageNum: number = 1, pageSize: number = 20) => {
  return $api.get<{
    rows: ShortVideo[]
    total: number
  }>(`/app/shorts/user/${userId}`, { pageNum, pageSize })
}